import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:excel_utils/pages/week/bean/RincosBean.dart';
import 'package:excel_utils/repository/week/rincos_repository.dart';

part 'rincos_state.dart';

class RincosCubit extends Cubit<RincosState> {

  RincosRepository rincosRepository;
  RincosCubit(this.rincosRepository) : super(RincosInitial());

  refresh() async {
    emit(RincosRefreshing(timestamp: DateTime.now().millisecondsSinceEpoch));
  }

  saveRincos({required List<RincosBean> rincosData}) async {
    emit(RincosSaveLoading());
    List<RincosBean> quotationRecordData = await rincosRepository.saveRincosData(rincosData: rincosData);
    emit(RincosSaveSuccessState(rincosData: rincosData));
  }

  getRincos({maps}) async {
    emit(RincosDataLoading());
    List<RincosBean> rincosData = await rincosRepository.getRincosData(maps: maps);
    emit(RincosDataSuccessState(rincosData: rincosData));
  }

  delRincos({required String rincosId}) async {
    emit(RincosDeleteLoading(rincosId: rincosId));
    String deleteQuotationRecordId =
    await rincosRepository.deleteRincosData(rincosId: rincosId);
    if (deleteQuotationRecordId != "-1") {
      emit(RincosDeleteSuccessState(rincosId: rincosId));
    } else {
      emit(RincosDeleteFailureState(message: "删除失败", rincosId: rincosId));
    }
  }

}
